class Error412
    constructor: (@message) ->


global.raise = (err)->
    if typeof(err) == 'string'
        throw new Error412(err)

    for k of err
        if err[k] != undefined
            throw new Error412(err)


module.exports = (ctx, next) =>
    try
        await next()
    catch e
        if e instanceof Error412
            ctx.response.status = 412
            ctx.body = e.message
        else
            throw e
    if undefined == ctx.body
        ctx.body = ''
